<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>slot</title>
  <script src="../../vue.js"></script>
</head>
<body>
  <div id="root">
    <my-header>
      <template #[divname]="{title}">
        <div>{{title}}</div>
      </template>
    </my-header>
  </div>
  <script>
    Vue.config.productionTip = false

    const MyHeader = {
      template: `
        <h1>
          <slot name="default"></slot>
          <slot name="div1" :title="title" :title2="title"></slot>
          <slot name="default">
            <div>默认值</div>  
          </slot>
        </h1>
      `,
      data() {
        return {
          title: 'message'
        }
      }
    }
    var vm = new Vue({
      el: '#root',
      components: {
        MyHeader
      },
      data: {
        msg: 'content',
        divname: 'div1'
      },
      mounted() {
        setTimeout(() => {
          console.log(this.message)
        }, 2000)
      },
    })
  </script>
</body>
</html>